package com.bcbim.common.util;

import com.bcbim.common.sys.Code;
import com.google.common.collect.Lists;

import java.util.List;
import java.util.Map;

/**
 * @Description: 码值工具类
 * @Author haoshuai
 * @Date 2020/9/21
 * @Version V1.0
 **/
public class MyCodeUtil {

    /**
     * @Description: 下拉列表添加"全部"码值
     * @Param: list 下拉列表码值集合
     * @Return: List<Code>
     * @Author: haoshuai
     * @Date: 2020/9/21
     */
    public static List<Code> addAllCode(List<Code> list) {
        Code code = new Code();
        code.setCode("").setValue("全部");
        list.add(0, code);
        return list;
    }

    /**
     * @Description: 码值map转码值list
     * @Param: 码值map
     * @Return: List<Code>
     * @Author: haoshuai
     * @Date: 2020/9/22
     */
    public static List<Code> sysCodeMapToList(Map<String, String> map) {
        List<Code> list = Lists.newArrayList();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            Code c = new Code();
            c.setCode(entry.getKey()).setValue(entry.getValue());
            list.add(c);
        }
        return list;
    }

    /**
     * @Description: 下拉列表添加"全部"码值
     * @Param: map
     * @Return: List<Code>
     * @Author: haoshuai
     * @Date: 2020/9/22
     */
    public static List<Code> addAllCodeForMap(Map<String, String> map) {
        List<Code> list = sysCodeMapToList(map);
        List<Code> resList = addAllCode(list);
        return resList;
    }

}
